<?php
require_once(DP_BASE_DIR."/modules/masterdata/mdstatus.class.php");
$status_id = intval( dPgetParam( $_GET, 'status_id', 0 ) );

// check permissions for this record
/*
$perms =& $AppUI->acl();
if (! ($canEdit = $perms->checkModuleItem( 'currencys', 'edit', $currency_id )) ) {
	$AppUI->setMsg('Access denied', UI_MSG_ERROR);
	$AppUI->redirect();
}
*/

// load the record data
$msg = '';
$row = new CMdStatus();

$canDelete = $row->canDelete( $msg, $status_id );
if($msg == $AppUI->_('statusDeleteUserError', UI_OUTPUT_JS)) {
	$userDeleteProtect=true;
}

if ($view) {
	$view = ' readonly="true"';
}
else {
	unset($view);
}

if (!$row->load( $status_id ) && $status_id > 0) {
	$AppUI->setMsg( 'Status' );
	$AppUI->setMsg( 'invalidID', UI_MSG_ERROR, true );
	$AppUI->redirect();
}
$q = new DBQuery();
$q->addTable('md_status');
$q->addQuery('status_code');
if (isset($row->status_code)) {
	$q->addWhere("status_id != $row->status_id");
}
$quoteCodeList = $q->loadColumn();
$qCL = '["' . implode('", "', $quoteCodeList) . '"]';

if (!$view) {
?>
<form name="MdStatusForm" action="?m=masterdata" method="post">
<input type="hidden" name="dosql" value="mdstatus_do_aed" />
<input type="hidden" name="status_id" value="<?=$status_id?>" />
<?}?>
<table border="0" cellpadding="8" cellspacing="0" width="400px">
<tr>
<td colspan="2" bgcolor="#E0E0E0"><b><?=$AppUI->_('Status Information')?></td>
</tr>
<tr>
	<td colspan="2">
		<table border="0" cellpadding="0" cellspacing="4" width="100%">
		<tr>
			<td align="right" valign="top"> * <?=$AppUI->_('Status type')?></td>
			<td>
				<select name="status_type" style="width: 200px">
					<option value="Resource" <?= (@$row->status_type == "Resource") ? "selected":""?> >Resource</option>
					<option value="Customer" <?= (@$row->status_type == "Customer") ? "selected":""?>>Customer</option>
					<option value="Supplier" <?= (@$row->status_type == "Supplier") ? "selected":""?>>Supplier</option>
					<option value="Unit" <?= (@$row->status_type == "Unit") ? "selected":""?>>Unit</option>
					<option value="Transportation" <?= (@$row->status_type == "Transportation") ? "selected":""?>>Transportation</option>
					<option value="Item" <?= (@$row->status_type == "Item") ? "selected":""?>>Item</option>
					<option value="Quotation" <?= (@$row->status_type == "Quotation") ? "selected":""?>>Quotation</option>
					<option value="Reference" <?= (@$row->status_type == "Reference") ? "selected":""?>>Reference</option>
				</select>
			</td>
		</tr>
		<tr>
			<td align="right" valign="top"> * <?=$AppUI->_('Code')?></td>
			<td>
				<input ftype=""  type="text" class="text" name="status_code" id="status_code"
				value="<?=@$row->status_code?>" maxlength="50" style="width: 98%" <?=$view?>/>
			</td>
		</tr>
		<tr>
			<td align="right" valign="top"> * <?=$AppUI->_('Name')?></td>
			<td>
				<input type="text" class="text" name="status_name" id="status_name"
					value="<?=@$row->status_name?>" maxlength="50" style="width: 98%" <?=$view?>/>
			</td>
		</tr>
		<tr>
			<td align="right"><?=$AppUI->_('Active')?></td>
			<td><input type="checkbox" name="status_active"
					value="1" <?=$view?> <?= (@$row->status_active == 1) ? "checked='true'":""?>/>
			</td>
		</tr>
		</table>
	</td>
</tr>
<tr>
	<td align="center" colspan="2" style="border-top: 1px solid #E0E0E0">
	<? if (!$view) { ?>
		<input type="submit" class="button" value="<?=$AppUI->_('Save')?>"/>
		<input type="button" class="button" value="<?=$AppUI->_('Cancel')?>" onClick="doCloseStatus()"/>
	<? } else { ?>
		<input type="button" class="button" value="<?=$AppUI->_('Close')?>" onClick="doCloseStatus()"/>
	<? } ?>
	</td>
</tr>
</table>
</form>
<div id="validation_rules" style="visibility: hidden; display: none">
	var fStatusCode = new LiveValidation('status_code');
	fStatusCode.add( Validate.Presence );
	fStatusCode.add( Validate.Exclusion , {within: <?=$qCL?>});

	var fStatusName = new LiveValidation('status_name');
	fStatusName.add( Validate.Presence );

	new Tips($$('.text'));
</div>